package com.scsj.supermarket.view.activity.settingmodel;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

import com.scsj.supermarket.R;
import com.scsj.supermarket.utils.SkipUtils;
import com.scsj.supermarket.view.activity.baseactivitymodel.BaseActivity;
import com.vondear.rxtools.view.dialog.RxDialogSureCancel;
import com.zcw.togglebutton.ToggleButton;

import static com.vondear.rxtools.RxIntentTool.getAppDetailsSettingsIntent;


/**
 * 设置中心
 */
public class SettingActivity extends BaseActivity implements View.OnClickListener{
    public static final String TAG = "设置中心";
    private LinearLayout setting_push_ll;
    private ToggleButton setting_toggle_btn;
    private LinearLayout setting_clear_cash_ll;
    private LinearLayout setting_funcrecall_ll;
    private LinearLayout setting_private_ll;
    private LinearLayout setting_privacy_ll;
    private LinearLayout setting_about_ll;

    @Override
    protected void createView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_setting);

        initToolbar();
        setToolbarTitle("设置");
        hasBack(true);
    }

    @Override
    protected void initView() {

        setting_push_ll =findViewById(R.id.setting_push_ll);
        setting_toggle_btn = findViewById(R.id.setting_toggle_btn);
        setting_clear_cash_ll = findViewById(R.id.setting_clear_cash_ll);
        setting_funcrecall_ll = findViewById(R.id.setting_funcrecall_ll);
        setting_private_ll = findViewById(R.id.setting_private_ll);
        setting_privacy_ll = findViewById(R.id.setting_privacy_ll);
        setting_about_ll = findViewById(R.id.setting_about_ll);

    }

    @Override
    protected void initListener() {
        setting_push_ll.setOnClickListener(this);
        setting_toggle_btn.setOnToggleChanged(new ToggleButton.OnToggleChanged() {
            @Override
            public void onToggle(boolean on) {

            }
        });
        setting_clear_cash_ll.setOnClickListener(this);
        setting_funcrecall_ll.setOnClickListener(this);
        setting_private_ll.setOnClickListener(this);
        setting_privacy_ll.setOnClickListener(this);
        setting_about_ll.setOnClickListener(this);
    }

    @Override
    protected void initData() {
    }

    @Override
    public void onClick(View view) {

        switch (view.getId()){
            case R.id.setting_push_ll:
//                startActivity(PushActivity.class);
                getAppDetailSettingIntent(this);
                break;
            case R.id.setting_clear_cash_ll:
                final RxDialogSureCancel rxDialogSureCancel = new RxDialogSureCancel(this);//提示弹窗
               rxDialogSureCancel.setContent("是否清除缓存");
                rxDialogSureCancel.setSureListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        rxDialogSureCancel.cancel();
                    }
                });
                rxDialogSureCancel.setCancelListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        rxDialogSureCancel.cancel();
                    }
                });
                rxDialogSureCancel.show();
                break;
            case R.id.setting_funcrecall_ll:
                startActivity(FunctionRecallActivity.class);
                break;
            case R.id.setting_privacy_ll:
//                startActivity(PrivacyActivity.class);
                break;
            case R.id.setting_about_ll:
                break;
        }
    }


    private void getAppDetailSettingIntent(Context context) {
        Intent localIntent = new Intent();
        localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (Build.VERSION.SDK_INT >= 9) {
            localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
            localIntent.setData(Uri.fromParts("package", getPackageName(), null));
        } else if (Build.VERSION.SDK_INT <= 8) {
            localIntent.setAction(Intent.ACTION_VIEW);
            localIntent.setClassName("com.android.settings","com.android.settings.InstalledAppDetails");
            localIntent.putExtra("com.android.settings.ApplicationPkgName", getPackageName());
        }
        startActivity(localIntent);
    }
}
